import 'package:flutter/material.dart';
import 'package:storage/model/user_name_entity.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart';

class AllGoodsDataSource extends DataGridSource {
  /// Creates the employee data source class with required details.
  AllGoodsDataSource({required List<UserNameEntity> employeeData}) {
    _dataList = employeeData
        .map<DataGridRow>((e) => DataGridRow(cells: [
              DataGridCell<int>(
                  columnName: '商品id', value: e.goodsId),
      DataGridCell<String>(
                  columnName: '商品名称', value: e.goodsName ?? ''),
      DataGridCell<String>(
                  columnName: '商品规格', value: e.goodsSpecification ?? ''),
              DataGridCell<double>(columnName: '商品价格', value: e.goodsPrice),
              DataGridCell<int>(columnName: '库存数量', value: e.inventoryQuantity),
              DataGridCell<double>(
                  columnName: '上次修改价格', value: e.lastEditPrice),
              DataGridCell<String>(
                  columnName: '入库时间', value: e.warehouseInTime??''),
              DataGridCell<String>(
                  columnName: '上次出库时间', value: e.lastWarehouseOutTime??''),
            ]))
        .toList();
  }

  List<DataGridRow> _dataList = [];

  @override
  List<DataGridRow> get rows => _dataList;

  @override
  DataGridRowAdapter buildRow(DataGridRow row) {
    return DataGridRowAdapter(
        cells: row.getCells().map<Widget>((e) {
      return Container(
        alignment: Alignment.center,
        decoration: const BoxDecoration(
            border: Border(
              right: BorderSide(
                  color: Colors.grey, width: 1),
              left:  BorderSide(
                  color: Colors.grey, width: 1),
            )),
        child: Text(e.value.toString()),
      );
    }).toList());
  }
}
